//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.das.metrocloud.ssoserver.controller;

import com.das.framework.common.extvo.ResultVO;
import com.das.framework.web.spring.controller.SupportController;
import com.das.metrocloud.ssoserver.config.AuthKeyConfig;
import com.das.metrocloud.ssoserver.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/auth/authorization"})
public class UserAuthorizationController extends SupportController {
    @Autowired
    private AuthorizationService authorizationService;
    @Autowired
    private AuthKeyConfig keyConfig;

    public UserAuthorizationController() {
    }

    @RequestMapping(
            method = {RequestMethod.POST}
    )
    @ResponseBody
    public ResultVO authorization(String token) {
        return this.authorizationService.authorization(token);
    }

    @ResponseBody
    @RequestMapping({"/userPubKey"})
    public ResultVO getServicePublicKey(String clientId, String secret) throws Exception {
        ResultVO resultVO = new ResultVO();
        resultVO.setData(this.keyConfig.getUserPubKey());
        resultVO.setMessage("Authentication Successful.");
        return resultVO;
    }

    @RequestMapping(
            value = {"/hasPermission"},
            method = {RequestMethod.POST}
    )
    @ResponseBody
    public ResultVO hasPermission(String token, String code) {
        log.debug(">>>>开始认证,Token::" + token + ", Code:" + code);
        return this.authorizationService.hasPermission(token, code);
    }
}
